In [1]:
%run ../common.ipynb
Read image
In [2]:
img = imread('mp.tif')
Find the center
In [3]:
center_x, center_y = [ x/2 for x in img.shape ]
Create a hann window mask
In [4]:
x, y = np.meshgrid(range(img.shape[1]), range(img.shape[0]))
r = np.sqrt((center_x - x)**2 + (center_y - y)**2)
mask = (np.cos(r/center_x*np.pi)+1)/2
mask[r>center_x] = 0
Apply the window and show images
In [6]:
wimg = img * mask
imshow(img)
imshow(wimg);
Do Fourier transform
In [7]:
fimg = fftshift(fft2(img))
fwimg = fftshift(fft2(wimg))
Show the difference of FT with and without Hann window
In [8]:
imshow(log(abs(fimg)), cmap="gray")
imshow(log(abs(fwimg)), cmap="gray");